/**
 * 作业管理——待提交
 */

import { LineChartOutlined } from '@ant-design/icons';
import { Link } from 'react-router-dom';
import { history } from 'umi';
import {
  DatePicker,
  Space,
  Input,
  Select,
  Table,
  Tag,
  Tabs,
  Button,
<<<<<<< HEAD
  Form,message
=======
  Form,
>>>>>>> 2bf1cc2a02320074a7d1489b29d5aba2d1c101f1
} from 'antd';
import React, { useState } from 'react';
import request from '@/http';
import All_style from '../../index.less';

const { RangePicker } = DatePicker;
const { TabPane } = Tabs;
const { Option } = Select;

const columns = [
  {
    title: '发布时间',
    dataIndex: 'createTime',
    key: 'createTime',
  },
  {
    title: '项目名称',
    dataIndex: 'courseName',
    key: 'courseName',
  },
  {
    title: '作业主题',
    dataIndex: 'title',
    key: 'title',
  },
  {
    title: '作业类型',
    dataIndex: 'workType',
    key: 'workType',
  },
  {
    title: '实训老师',
    dataIndex: 'teacherName',
    key: 'teacherName',
  },
  {
    title: '计划完成时间',
    dataIndex: 'completeDate',
    key: 'completeDate',
  },
  {
    title: '作业完成状态',
    dataIndex: 'workStatus',
    key: 'workStatus',
  },
  // {
  //   title: '实际完成时间',
  //   dataIndex: 'wc_completetim',
  //   key: 'wc_completetim',
  // },
  // {
  //   title: '得分',
  //   dataIndex: 'score',
  //   key: 'score',
  // },
  {
    title: '操作',
    key: 'action',
    render: (row: any) => (
      <>
        <Button
          type="link"
          onClick={() => {
            history.push(`/Student/TaskManagement/StudentAnswer?id=${row.id}`);
          }}
        >
          答题
        </Button>
      </>
    ),
  },
];
const dataOld = [
  {
    completeDate: '',
    ompleteTime: '',
    courseName: '',
    createTime: '',
    id: '',
    score: '',
    teacherName: '',
    title: '',
    workStatus: '',
    workType: '',
    key: '',
    workId: '',
    active: '',
  },
];
const submit = (props: any) => {
  // 绑定下拉框的接口
  const [courseName, setCourseName] = React.useState([]);
  const getCourseName = async () => {
    const CourseName: any = await request.post(
      '/common/getCourse',{
        isGraduation:1
      }
    );
    setCourseName(CourseName.date);
  };

  // 实训老师下拉框接口绑定
  const [trTeacherName, setTrTeacherName] = React.useState([]);
  const getTrTeacherName = async () => {
    const TrTeacherName: any = await request.get('/common/getTrainingTeacher');
    console.log(TrTeacherName);
    if(TrTeacherName.code == '200'){
       setTrTeacherName(TrTeacherName.date);
    }else{
     message.error(TrTeacherName.message)
    }   
  };
  /**------------------------------------------------------------------------------ */
  const [data, setData] = React.useState(dataOld);
  //显示
  const [formObject] = Form.useForm();
  interface pageInfoTypes {
    current: number;
    pageSize: number;
    total: number;
    onChange: any;
  }
  const onCurrentChange = (page: any, pageSize: any) => {
    loadData(page, pageInfo.pageSize);
  };
  const [pageInfo, setPageInfo] = useState<pageInfoTypes>({
    current: 1,
    pageSize: 5,
    total: 0,
    onChange: onCurrentChange,
  });
  const loadData = async (current: any, pageSize: any) => {
    // const datas = await formObject.validateFields();
    const result: any = await request.post(
      '/work-submit-info-entity/jobManagement_s',
      {
        current: current,
        size: pageSize,
        type: '待提交',
        // ...datas,
        // vacationEndDate: datas?.createTime
        //   ? datas?.createTime[1]?.format('YYYY-MM-DD HH:mm:ss')
        //   : '',
        // vacationBeginDate: datas?.createTime
        //   ? datas?.createTime[0]?.format('YYYY-MM-DD HH:mm:ss')
        //   : '',
        // workPlanTime: datas?.completeDate
        //   ? datas?.completeDate?.format('YYYY-MM-DD HH:mm:ss')
        //   : '',
      },
    );
    console.log(result);
    if (result.code == '200') {
      const newData = result.date.info.map((d: any, index: any) => {
        return {
          key: `k_${index}`,
          ...d,
        };
      });
      setData(newData);
      setPageInfo({
        current: result?.data?.paginationData?.currentPage,
        pageSize: result?.data?.paginationData?.number,
        total: result?.data?.paginationData?.sum,
        onChange: pageInfo.onChange,
      });
    }
  };

  const selextLoadData = async (current: any, pageSize: any) => {
    const datas = await formObject.validateFields();
    const result: any = await request.post(
      '/work-info-entity/selectHomeworkInfo',
      {
        current: current,
        size: pageSize,
        type: '待提交',
        ...datas,
        vacationEndDate: datas?.createTime
          ? datas?.createTime[1]?.format('YYYY-MM-DD HH:mm:ss')
          : '',
        vacationBeginDate: datas?.createTime
          ? datas?.createTime[0]?.format('YYYY-MM-DD HH:mm:ss')
          : '',
        workPlanTime: datas?.completeDate
          ? datas?.completeDate?.format('YYYY-MM-DD HH:mm:ss')
          : '',
      },
    );
    console.log(result);
    if (result.code == '200') {
      const newData = result.date.info.map((d: any, index: any) => {
        return {
          key: `k_${index}`,
          ...d,
        };
      });
      setData(newData);
      setPageInfo({
        current: result?.data?.paginationData?.currentPage,
        pageSize: result?.data?.paginationData?.number,
        total: result?.data?.paginationData?.sum,
        onChange: pageInfo.onChange,
      });
    }
  };
  //查询

  //重置按钮
  const onReset = () => {
    formObject.resetFields();
    loadData(pageInfo.current, pageInfo.pageSize);
  };
  React.useEffect(() => {
    loadData(pageInfo.current, pageInfo.pageSize);
      getCourseName();
      // getWorkType();
      getTrTeacherName();
  }, []);

  return (
    <div className={All_style.box}>
      <Form name="SelectLeaveForm" form={formObject} preserve={false}>
        <div>
          <Form.Item
            name="createTime"
            label="发布时间："
            style={{ float: 'left' }}
            className={All_style.data}
          >
            <RangePicker showTime className={All_style.select} />
          </Form.Item>

          <Form.Item
            name="courseName"
            label="项目名称："
            style={{ float: 'left' }}
            className={All_style.formItem}
          >
            <Select placeholder="请选择" className={All_style.select}>
              {courseName.map((c:any, index) => {
                return (
                  <Option key={`k_${index}`} value={c.format}>
                    {c.format}
                  </Option>
                );
              })}
            </Select>
          </Form.Item>

          <Form.Item
            name="title"
            label="作业主题："
            style={{ float: 'left' }}
            className={All_style.formItem}
          >
            <Input placeholder="请录入" className={All_style.select}></Input>
          </Form.Item>
            <Form.Item
              name="workType"
              label="作业类型："
              style={{ float: 'left' }}
              className={All_style.formItem}
            >
              <Select placeholder="请选择" className={All_style.select}>
                <Option key= '0' value='0'>平时作业</Option>
                <Option key= '1' value='1'>阶段性作业</Option>
                <Option key= '2' value='2'>最终交互作业</Option>
              </Select>
            </Form.Item>

            <Form.Item
            name="teacherName"
            label="实训老师："
            style={{ float: 'left' }}
            className={All_style.formItem}
          >
            <Select defaultValue="请选择" className={All_style.select}>
              {trTeacherName.map((c: any, index: any) => {
                return (
                  <Option key={`k_${index}`} value={c.format}>
                    {c.format}
                  </Option>
                );
              })}
            </Select>
          </Form.Item>

            <Form.Item
              name="completeDate"
              label="计划完成时间："
              style={{ float: 'left' }}
              className={All_style.data}
            >
              <DatePicker showTime className={All_style.select} />
            </Form.Item>
          <div style={{ clear: 'both', float: 'right', marginRight: 80 }}>
            <Button
              className={All_style.button}
              onClick={() => selextLoadData(pageInfo.current, pageInfo.pageSize)}
            >
              查询
            </Button>
            <Button
              className={All_style.button2}
              htmlType="button"
              onClick={onReset}
            >
              重置
            </Button>
          </div>
        </div>
      </Form>
      <Table
        columns={columns}
        dataSource={data}
        className={All_style.table}
        pagination={pageInfo}
      />
    </div>
  );
};
export default submit;
